package com.yegrina.twt.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.yegrina.twt.domain.SubmitReportCommand;


public class SubmitReportValidator implements Validator{


	public boolean supports(Class<?> clazz) {
		
		
		return SubmitReportCommand.class.isAssignableFrom(clazz);
	}


	public void validate(Object target, Errors errors) {
		
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "subject", "required");
		SubmitReportCommand command = (SubmitReportCommand)target;
		if(command.getReportFile() == null || command.getReportFile().isEmpty()){
			errors.rejectValue("reportFile", "required");
		}
	}

}
